package com.chenjj.java.juc.tools.countdownlatch;

import java.util.concurrent.CountDownLatch;

public abstract class AbstractHealthCheckService implements Runnable {
    protected CountDownLatch _latch;
    protected String _serviceName;
    protected boolean _serviceUp;

    public boolean is_serviceUp() {
        return _serviceUp;
    }



    public AbstractHealthCheckService(String serviceName,CountDownLatch latch){
        this._latch = latch;
        this._serviceName = serviceName;
        this._serviceUp = false;
    }


    @Override
    public void run() {
        try {
            verifyService();
            this._serviceUp = true;
        }catch (Throwable e){
            e.printStackTrace();
            this._serviceUp = false;
        }finally {
            if (_latch != null){
                _latch.countDown();
            }
        }
    }

    public abstract void verifyService();
}
